import { HTTP } from '../utils/http-p'

class KeywordsModel extends HTTP{
    key = 'q'
    maxLength = 10

    getHistory(){
        const words = wx.getStorageSync(this.key)
        if(!words){
            return []
        }
        return words;
    }

    setHistory(word){
        let words = this.getHistory()
        const has = words.includes(word)
        if(!has){
            const length = words.length
            if(length >= this.maxLength){
                words.pop()
            }
            words.unshift(word)
            wx.setStorageSync(this.key,words)

        }
    }

    getHot(){
        return this.request({
            url:'/book/hot_keyword'
        })
    }
}

export {KeywordsModel}